/*
 SGSortingGameViewController.h
 Date Created: Feburary 24, 2010
 
 Authors: Karanvir Gill <viper1029@gmail.com>
				  Frank Lau <flaua@sfu.ca>
          Karol Krizka <kkrizka@gmail.com>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import <UIKit/UIKit.h>

#import <AVFoundation/AVAudioPlayer.h>

#import "SGRecyclableItemView.h"
#import "SGSortingGameLevel.h"
#import "SGBin.h"
#import "SGSortingGame.h"

#import "../profilemngt/PMProfile.h"


@interface SGSortingGameViewController : UIViewController {
  // UI References
  UILabel *levelScoreLabel;
  UILabel *totalScoreLabel;
  UILabel *livesLeftLabel;
  UILabel *levelLabel;
  UILabel *itemsLeftLabel;

  // Information about the current game
  NSMutableArray *unexplainedItemTypes; // Used for tutorial mode
  
  // Some statistics
  SGSortingGame *sortingGame;                 // The object that holds information about the current game
  SGSortingGameLevel *sortingGameLevel;
  
	//Sound for items falling in bins
	AVAudioPlayer *wrongBinSound;
	AVAudioPlayer *correctBinSound;	
	
  // Controls the flow of the game
  NSMutableArray *itemsOnScreen;
  NSMutableArray *binsOnScreen;
  
  NSTimer *moveTimer; // Move items across the screen
  NSTimer *createTimer; // Create new items
	
}

@property (nonatomic,retain) SGSortingGameLevel *sortingGameLevel;
@property (nonatomic,retain) IBOutlet UILabel *levelScoreLabel;
@property (nonatomic,retain) IBOutlet UILabel *totalScoreLabel;
@property (nonatomic,retain) IBOutlet UILabel *livesLeftLabel;
@property (nonatomic,retain) IBOutlet UILabel *levelLabel;
@property (nonatomic,retain) IBOutlet UILabel *itemsLeftLabel;

/**
 * Constructor for sorting game view controller that displays the game described
 * in |sortingGame| parameter.
 *
 * \param sortingGame Score, current level and so on
 */
- (SGSortingGameViewController*)initWithSortingGame:(SGSortingGame *)sortingGame;

/**
 * Stops the timers that update the game. This effectively pauses the game,
 * but does not change the UI.
 */
- (void)stopTimers;

/**
 * Starts the timers, so the game continues progressing.
 */
- (void)startTimers;


/**
 * Pauses the game and shows the SGPauseViewController
 */
- (IBAction)showPauseMenu:(id)sender;

/**
 * Turns tutorial mode on/off for the current player
 */
- (IBAction)tutorialModeOnOff:(id)sender;

/**
 * Creates a recyclable item and shows it on display. It will only create items 
 * if numberOfItemsAlreadyDisplayed is less than totalNumberOfItemsToDisplay.
 * The recyclable type to create is determined by arrayOfItemsToDisplay.
 */
- (void)createItem;

/**
 * Moves all the objects on the screen down by a certain number of pixels 
 * (determined by the level). Checks if the objects are over a bin, in the
 * garbage or anywhere else on the screen. If an item have been picked up 
 * then it will disapper when dropped, and points will only be given if its 
 * dropped in the correct bin.
 */
- (void)moveItems;

/**
 * Used to place the bins on the screen. Adds the created bins to the
 * binsOnScreen array.
 */
- (void)drawBins;

/**
 * Reload view to show the information of the current level
 */
- (void) reloadView;

/**
 *show level Summary Screen
 */
- (void)showLevelSummary;

/**
 *show end game screen
 */
- (void)showEndGame;

/**
 * Checks what bin an item is on top of, such that it would be dropped there.
 *
 * If the item icon is on top of several bins, the one with the largest overlap
 * is picked.
 *
 * \return bin that the item is on top of, nil of none
 */
- (SGBin *)binItemIsOn:(SGRecyclableItemView *)item;
 
/**
 * Animates a chechmark at a given position. The animation is creating the
 * checkmark, having it float upwards and dissapear.
 *
 * \param imageName The image that to use for the checkmark.
 * \param pos The position (center of view) at which to start the animation
 */
- (void)animateCheckmark:(NSString *)imageName fromLocation:(CGPoint)pos;
@end
